<?php

namespace app\common\model;

use think\Model;

class PaymentRecord extends Model
{
    // 表名
    protected $name = 'payment_record';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';

    // 定义时间戳字段名
    protected $updateTime = false; // 没有 updatetime 字段

    // 默认查询条件
    protected $defaultScope = ['is_delete' => 0];

    // 全局查询范围
    public function scopeDefault($query)
    {
        return $query->where('is_delete', 0);
    }

    public function customer()
    {
        return $this->belongsTo('app\\common\\model\\Customer', 'customer_id', 'id')->field('id,customerName,uidipin');
    }

    public function staff()
    {
        return $this->belongsTo('app\\common\\model\\User', 'staff_id', 'id')->field('id,name');
    }
    public function contract()
    {
        return $this->belongsTo('app\\common\\model\\Contracts', 'contract_id', 'id')->field('id,contractName');
    }
    public function plan()
    {
        return $this->belongsTo('app\common\model\PaymentPlan', 'plan_id', 'id')->field('id,period');
    }
}